<#include "../../common/com.html" /> <@layout>
<!-- ace styles -->
<link rel="stylesheet" href="${ctx}/static/assets/css/ace.min.css" />

    <script src="${ctx}/static/inc/platform/js/ajax.js"></script>
    <link rel="stylesheet" href="${ctx}/static/kindeditor/themes/default/default.css" />
    <script charset="utf-8" src="${ctx}/static/kindeditor/kindeditor-min.js"></script>
    <script charset="utf-8" src="${ctx}/static/kindeditor/lang/zh_CN.js"></script>
    <script charset="utf-8" src="${ctx}/static/kindeditor/plugins/code/prettify.js"></script>
    <script src="${ctx}/static/js/jquery.tools.js"></script>

<script type="text/javascript">

    function saveModel() {
        if(Validator.Validate(document.getElementById('form1'))){
        } else {
            return;
        }
//       var m=$("#nr").val();
//        m = m.replace(/(\t)/g, "");
//       m = m.replace(/(\n)/g, "");
//        alert(m);
////        $("#xmjj").attr("value",m);
// 同步数据后可以直接取得textarea的value
        var id=document.getElementById("id").value;
        url = '';
        if(id==""){
            url = '${ctx}/cgglWp/savewp';
        }     else{
            url = '${ctx}/cgglWp/updatewp';
        }
        $('#form1').form('submit', {
            url : url,
            onSubmit : function() {
                return $(this).form('validate');
            },
            success : function(data) {
                alert(data);
                parent.location.reload();
            }
        });

    }
    
</script>
<body>
	<div class="page-content" style="overflow: hidden">
		<div class="row-fluid">
			<div class="span6">
				<form class="form-horizontal" id="form1" method="post">
					<input type="hidden" name="id" id="id">
					<div class="control-group">
						<label class="control-label">商品名称:</label>
						<div class="controls">
							<input id="wpmc" name="wpmc" type="text"
								style="min-height: 24px;" dataType="Require" msg="请输入商品名称"
								maxlength="12" />

						</div>
					</div>
					<div class="control-group">
						<label class="control-label">所属类别：</label>
						<div class="controls">
							${name}  <input type="hidden"
								name="lbid" id="lbid" style="min-height: 24px;" value="${lbid}">
						</div>
					</div>
					<div class="control-group">
						<label class="control-label">商品编号：</label>
						<div class="controls">
							<input id="wpbh" name="wpbh" type="text"
								style="min-height: 24px;" dataType="Require" msg="请输入商品编号"
								maxlength="10" />
						</div>
					</div>

					<div class="control-group">
						<label class="control-label">商品单位：</label>
						<div class="controls">
							<select name="wpdw" id="wpdw">
								<option value="" selected></option>
								<option value="件">件</option>
								<option value="个">个</option>
								<option value="条">条</option>
								<option value="次">次</option>
								<option value="公斤">公斤</option>
								<option value="台">台</option>
								<option value="米">米</option>
								<option value="箱">箱</option>
								<option value="卷">卷</option>
								<option value="套">套</option>
								<option value="包">包</option>
								<option value="副">副</option>
								<option value="双">双</option>
								<option value="只">只</option>
								<option value="吨">吨</option>
							</select>
						</div>
					</div>
<div class="control-group">
						<label class="control-label">库存数量：</label>
						<div class="controls">
							<input id="kcsl" name="kcsl" type="text"
								style="min-height: 24px;"  easyui-numberbox "  precision="1" maxlength="7" value="0" />
						</div>
					</div>

<div class="control-group">
						<label class="control-label">库存上限：</label>
						<div class="controls">
							<input id="kcsx" name="kcsx" type="text"
								style="min-height: 24px;"  easyui-numberbox "  precision="1" maxlength="7" value="0" />
						</div>
					</div>
					<div class="control-group">
						<label class="control-label">库存下限：</label>
						<div class="controls">
							<input id="kcxx" name="kcxx" type="text"
								style="min-height: 24px;"  easyui-numberbox "  precision="1" maxlength="7" value="0" />
						</div>
					</div>

					<div class="control-group">
						<label class="control-label">销售单价（元）：</label>
						<div class="controls">
							<input id="ckdj" name="ckdj" type="text"
								style="min-height: 24px;"  class="easyui-numberbox"  precision="1" maxlength="7" />
						</div>
					</div>
					
					<div class="control-group">
						<label class="control-label">提成方式：</label>
						<div class="controls">
							<select name="sptcfs" id="sptcfs">
								<option value="" selected>无</option>
								<option value="1" >按销售比例提成</option>
								<option value="2">按件提成</option>
							</select>
						</div>
					</div>
					
					<div class="control-group">
					
						<label class="control-label">商品提成：(如果是百分比提成 百分之1直接填入 1.0)</label>
						<div class="controls">
							<input id="sptc" name="sptc" type="text"
								style="min-height: 24px;"  class="easyui-numberbox"  precision="1" maxlength="5" />
						</div>
					</div>
					
					<div class="control-group">
						<label class="control-label">销售状态：</label>
						<div class="controls">
							<select name="yxbz" id="yxbz">
								<option value="1" selected>正常销售</option>
								<option value="0">停止销售</option>
								<option value="2">折价销售</option>
								
							</select>
						</div>
					</div>

			<!-- 		<div class="control-group">
						<label class="control-label">显示顺序：</label>
						<div class="controls">
							<input id="dsporder" name="dsporder" type="text" class="easyui-number"
								style="min-height: 24px;" />
						</div>
					</div> -->
					<div class="control-group content">
						<div class="controls">
				           <input id="archivesfileid" name="archivesfileid" type="hidden"  value="" />
							<a class="btn btn-info btn-small" onclick="saveModel()">确定 </a>
							&nbsp; &nbsp;&nbsp;&nbsp; <a
								class="btn btn-danger btn-small bigger-110"
								onclick="window.location.href='${ctx}/cgglWp/add?id=${lbid}&name=${name}&pid=${pid}'">取消 </a>
						</div>
					</div>
				</form>
			</div>
			
			
			<div class="span6">
			
            <small>
              <a class="btn btn-info btn-mini"  id="image1" >选择图片 </a>（本地上传）

            </small>
				 <ul id="migui" class="ace-thumbnails">
				 <#if pic ??>
				    <#list pic as m>
				<li id='li${(m.id)!}'> <a  data-rel='colorbox'>
				 <img  src='${(m.path)!}'   style='width:100px;height:100px;'/><div class='text'>
                <div class='inner'>${(m.filename)!}</div>   </div></a>
               <div class='tools tools-bottom'>
                 <a href='#' onclick="dels('${(m.path)!}','${(m.id)!}')" >  
                <i class='icon-remove red  '></i></a></div> </li>
				  </#list>
					</#if>
				</ul>


			</div>
			
			
		</div>
	</div>
<form class="form-inline" id="myform">
    <input type="hidden" name="ids" id="ids">
    <input type="hidden" name="filename" id="filename">

</form>

</body>
<script>
KindEditor.ready(function(K) {
	var archivesfileid= document.getElementById("archivesfileid").value;
    var editor = K.editor({
        cssPath : '${ctx}/static/kindeditor/plugins/code/prettify.css',
        uploadJson : '${ctx}/upload/upload?archivesfileid='+archivesfileid,
        fileManagerJson : '${ctx}/uploadMedia/manageImg',
        allowFileManager : true
    });
    K('#image1').click(function() {
        editor.loadPlugin('image', function() {
            editor.plugin.imageDialog({
                showRemote : false,
                clickFn : function(url, title, width, height, border, align) {
                	
                	var htm="<li id='li"+width+"'> <a  data-rel='colorbox'>"+
				 "  <img  src='"+url+"'   style='width:100px;height:100px;'/><div class='text'>"+
                 "<div class='inner'>"+title+"</div>   </div></a>"+
                 "<div class='tools tools-bottom'>"+
                 "<a href='#' onclick=\"dels('"+url+"','"+width+"')\" >  "+
                 "<i class='icon-remove red  '></i></a></div> </li>";
                	$("#migui").append(htm);
                    editor.hideDialog();
                }
            });
        });
    });
});
/**
 * 删除文件
 */
function dels(filename,id){
	
    url = '/upload/delfile/';
    $("#ids").attr("value",id);
    $("#filename").attr("value",filename);
    $('#myform').form('submit', {
        url : url,
        onSubmit : function() {
        },
        success : function(data) {
            // 回填页面
            alert(data);
            $("#li"+id).remove();
          //  window.location.reload();
        }
    });
}

</script>
<script>
var id=""; 
    <#list list as m>
     id= '${(m.id)!}';
   document.getElementById("id").value  = '${(m.id)!}';
    document.getElementById("wpbh").value  =  '${(m.wpbh)!}';
    document.getElementById("wpmc").value  =  '${(m.wpmc)!}';
    document.getElementById("wpdw").value  =  '${(m.wpdw)!}';
    document.getElementById("ckdj").value  =  '${(m.ckdj)!}';
    document.getElementById("yxbz").value  =  '${(m.yxbz)!}';
    document.getElementById("archivesfileid").value= '${(m.archivesfileid)!}';
    document.getElementById("kcsl").value  =  '${(m.kcsl)!}';
    document.getElementById("sptc").value  =  '${(m.sptc)!}';
    document.getElementById("kcsx").value  =  '${(m.kcsx)!}';
    document.getElementById("kcxx").value  =  '${(m.kcxx)!}';
    document.getElementById("sptcfs").value  =  '${(m.sptcfs)!}';

    
  </#list>


  jQuery(function($) {
	  if(id ==""){
		  var archivesfileid =Math.uuid(32, 10);
		  document.getElementById("archivesfileid").value=archivesfileid;
	  }
  });

</script>
</@layout>

